<?php

    /**
     * This is the model class for table "{{customerloanpayment}}".
     *
     * The followings are the available columns in table '{{customerloanpayment}}':
     * @property integer $id
     * @property integer $loansetting_id
     * @property string $loan_code
     * @property integer $customer_id
     * @property string $customer_code
     * @property integer $installment_no
     * @property string $payment
     * @property integer $is_last_payment
     * @property string $pay_on_date
     * @property string $paid_on_date
     * @property string $paid_amount
     * @property string $remark
     * @property integer $clearedby_loan_id
     * @property string $createdate
     * @property integer $updatedby_user_id
     * @property string $modifydate
     */
    class CustomerLoanPayment extends CActiveRecord {

        /**
         * @return string the associated database table name
         */
        public function tableName() {
            return '{{customerloanpayment}}';
        }

        /**
         * @return array validation rules for model attributes.
         */
        public function rules() {
            // NOTE: you should only define rules for those attributes that
            // will receive user inputs.
            return array(
                array('paid_on_date, paid_amount', 'required'),
                array('loansetting_id, customer_id, installment_no, is_last_payment, updatedby_user_id', 'numerical', 'integerOnly' => true),
                array('loan_code, customer_code', 'length', 'max' => 20),
                array('payment, paid_amount', 'length', 'max' => 15),
                array('remark', 'length', 'max' => 200),
                array('pay_on_date, paid_on_date', 'safe'),
                // The following rule is used by search().
                // @todo Please remove those attributes that should not be searched.
                array('id, loansetting_id, loan_code, customer_id, customer_code, installment_no, payment, is_last_payment, pay_on_date, paid_on_date, paid_amount, remark, clearedby_loan_id, createdate, updatedby_user_id, modifydate', 'safe', 'on' => 'search'),
            );
        }

        /**
         * @return array relational rules.
         */
        public function relations() {
            // NOTE: you may need to adjust the relation name and the related
            // class name for the relations automatically generated below.
            return array(
                'loansetting' => array(self::BELONGS_TO, 'CustomerLoanSetting', 'loansetting_id'),
            );
        }

        /**
         * @return array customized attribute labels (name=>label)
         */
        public function attributeLabels() {
            return array(
                'id' => 'ID',
                'loansetting_id' => t('Loansetting'),
                'loan_code' => t('Loan Code'),
                'customer_id' => t('Customer'),
                'customer_code' => t('Customer Code'),
                'installment_no' => t('Installment No.'),
                'payment' => t('Payment'),
                'is_last_payment' => t('Is Last Payment?'),
                'pay_on_date' => t('On Date'),
                'paid_on_date' => t('Paid on Date'),
                'paid_amount' => t('Paid Amount'),
                'remark' => t('Remark'),
                'updatedby_user_id' => t('Updated by User'),
                'clearedby_loan_id' => t('Cleared by Loan ID'),
                'createdate' => t('Created Date'),
                'modifydate' => t('Modified Date'),
            );
        }

        /**
         * Retrieves a list of models based on the current search/filter conditions.
         *
         * Typical usecase:
         * - Initialize the model fields with values from filter form.
         * - Execute this method to get CActiveDataProvider instance which will filter
         * models according to data in model fields.
         * - Pass data provider to CGridView, CListView or any similar widget.
         *
         * @return CActiveDataProvider the data provider that can return the models
         * based on the search/filter conditions.
         */
        public function search() {
            // @todo Please modify the following code to remove attributes that should not be searched.

            $criteria = new CDbCriteria;

            $criteria->compare('id', $this->id);
            $criteria->compare('loansetting_id', $this->loansetting_id);
            $criteria->compare('loan_code', $this->loan_code, true);
            $criteria->compare('customer_id', $this->customer_id);
            $criteria->compare('customer_code', $this->customer_code, true);
            $criteria->compare('installment_no', $this->installment_no);
            $criteria->compare('payment', $this->payment, true);
            $criteria->compare('is_last_payment', $this->is_last_payment);
            $criteria->compare('pay_on_date', $this->pay_on_date, true);
            $criteria->compare('paid_on_date', $this->paid_on_date, true);
            $criteria->compare('paid_amount', $this->paid_amount, true);
            $criteria->compare('remark', $this->remark, true);
            $criteria->compare('createdate', $this->createdate, true);
            $criteria->compare('updatedby_user_id', $this->updatedby_user_id);
            $criteria->compare('clearedby_loan_id', $this->clearedby_loan_id);
            $criteria->compare('modifydate', $this->modifydate, true);

            return new CActiveDataProvider($this, array(
                'criteria' => $criteria,
            ));
        }

        /**
         * Returns the static model of the specified AR class.
         * Please note that you should have this exact method in all your CActiveRecord descendants!
         * @param string $className active record class name.
         * @return CustomerLoanPayment the static model class
         */
        public static function model($className = __CLASS__) {
            return parent::model($className);
        }

    }

